package com.ten.course.controller;

import com.ten.common.core.entity.EduChapter;
import com.ten.common.core.vo.Result;
import com.ten.course.service.CourseChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author ：张成（3092211427@qq.com）
 * @date ：Created in 2022/12/21 22:59
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/course/chapter")
@Api(tags = "课程章节接口")
public class CourseChapterController {
    @Autowired
    private CourseChapterService courseChapterService;

    /**
     * 根据课程id查询课程的章节
     *
     * @param courseId 课程id
     * @return
     */
    @ApiOperation(value = "根据课程id查询课程的章节")
    @PostMapping("findChapterById/{courseId}")
    public Result<List<EduChapter>> findChapterById(@PathVariable String courseId) {
        return courseChapterService.findChapterById(courseId);
    }

    @ApiOperation(value = "根据章节id对章节进行更新或者添加")
    @PostMapping("insertChapterWithCourseId")
    public Result insertChapterWithCourseId(@RequestBody EduChapter eduChapter) {
        return courseChapterService.insertChapterWithCourseId(eduChapter);
    }

    /**
     * 删除章节
     * @param eduChapter
     * @return
     */
    @ApiOperation(value = "删除章节")
    @PostMapping("deleteChapterWithCourseId")
    public Result deleteChapterWithCourseId(@RequestBody EduChapter eduChapter){
        return courseChapterService.deleteChapterWithCourseId(eduChapter);
    }
}